home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xcmd / dartxcmd.sit / Dartmouth XCMD's 3.1 / card_10571.txt < prev    next >
Encoding:
Text File  |  1989-06-02  |  8.8 KB  |  279 lines

  1. -- card: 10571 from stack: in.1
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 8327
  5. -- name: SerialHandler
  6. ----- HyperTalk script -----
  7. on Install
  8.   put ChooseTargetStack() into it
  9.   InstallResource XFCN,SerialHandler,it
  10. end Install
  11.  
  12. on opencard
  13.   set the visible of card field "oh well" to false
  14.   set the visible of button "put" to false
  15.   set the visible of button "get" to false
  16.   pass opencard
  17. end opencard
  18.  
  19.  
  20.  
  21. -- part 3 (button)
  22. -- low flags: 00
  23. -- high flags: 8003
  24. -- rect: left=51 top=298 right=320 bottom=151
  25. -- title width / last selected line: 0
  26. -- icon id / first selected line: 0 / 0
  27. -- text alignment: 1
  28. -- font id: 0
  29. -- text size: 12
  30. -- style flags: 0
  31. -- line height: 16
  32. -- part name: SerialHandler
  33. ----- HyperTalk script -----
  34. on mouseUp
  35.   set the visible of card field "oh well" to true
  36.   answer "Do you?" with "Yes"or"No"
  37.   set the visible of card field "oh well" to false
  38.   if it is "Yes" then
  39.     set the visible of button "put" to true
  40.     set the visible of button "get" to true
  41.   end if
  42. end mouseUp
  43.  
  44.  
  45.  
  46. -- part 5 (field)
  47. -- low flags: 01
  48. -- high flags: 2007
  49. -- rect: left=18 top=32 right=284 bottom=486
  50. -- title width / last selected line: 0
  51. -- icon id / first selected line: 0 / 0
  52. -- text alignment: 0
  53. -- font id: 3
  54. -- text size: 10
  55. -- style flags: 0
  56. -- line height: 13
  57. -- part name: Documentation
  58.  
  59.  
  60. -- part 8 (field)
  61. -- low flags: 80
  62. -- high flags: 0002
  63. -- rect: left=18 top=24 right=285 bottom=482
  64. -- title width / last selected line: 0
  65. -- icon id / first selected line: 0 / 0
  66. -- text alignment: 1
  67. -- font id: 0
  68. -- text size: 12
  69. -- style flags: 0
  70. -- line height: 16
  71. -- part name: oh well
  72.  
  73.  
  74. -- part 9 (button)
  75. -- low flags: 80
  76. -- high flags: A003
  77. -- rect: left=154 top=293 right=311 bottom=189
  78. -- title width / last selected line: 0
  79. -- icon id / first selected line: 0 / 0
  80. -- text alignment: 1
  81. -- font id: 0
  82. -- text size: 12
  83. -- style flags: 0
  84. -- line height: 16
  85. -- part name: Put
  86. ----- HyperTalk script -----
  87. on mouseUp
  88.   -- You may have to change the parameter list to suit your configuration
  89.   -- NOTE: This button is a self contained operation of open, put,close.
  90.   --       You DO NOT have to open and close every time you get or put.
  91.   --       Just open once and start once, like when you open and close
  92.   --       your stack.
  93.   set the cursor to watch
  94.   get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  95.   if it is not empty then
  96.     put "Error: "&&it&&" (See script of "put" button)"
  97.   end if
  98.   put the number of lines in the script of me into nl
  99.   repeat with i = 1 to nl
  100.     get line i of the script of me
  101.     get Serialhandler("put","A",it&return&numToChar(10))
  102.   end repeat
  103.   if it is not empty then
  104.     put "Error: "&&it
  105.   end if
  106.   get Serialhandler("close","A")
  107. end mouseUp
  108.  
  109.  
  110.  
  111. -- part 10 (button)
  112. -- low flags: 80
  113. -- high flags: 8003
  114. -- rect: left=187 top=306 right=324 bottom=223
  115. -- title width / last selected line: 0
  116. -- icon id / first selected line: 0 / 0
  117. -- text alignment: 1
  118. -- font id: 0
  119. -- text size: 12
  120. -- style flags: 0
  121. -- line height: 16
  122. -- part name: Get
  123. ----- HyperTalk script -----
  124. on mouseUp
  125.   -- You may have to change the parameter list to suit your configuration
  126.   -- NOTE: This button is a self contained operation of open, get,close.
  127.   --       You DO NOT have to open and close every time you get or put.
  128.   --       Just open once and start once, like when you open and close
  129.   --       your stack.
  130.   set the hilite of me to true
  131.   set the cursor to watch
  132.   get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
  133.   set the visible of card field "got" to true
  134.   put empty into card field "got"
  135.   put "Click the mouse when done."
  136.   put "Characters received on the serial port will appear below:" &return&return into card field "got"
  137.   repeat while the mouse is up
  138.     get SerialHandler("get","A",60)
  139.     put it after card field "got"
  140.   end repeat
  141.   get SerialHandler("close","A")
  142.   set the visible of card field "got" to false
  143.   set the hilite of me to false
  144.   put empty into msg
  145.   hide msg
  146. end mouseUp
  147.  
  148.  
  149.  
  150. -- part 11 (field)
  151. -- low flags: 80
  152. -- high flags: 0007
  153. -- rect: left=18 top=32 right=285 bottom=481
  154. -- title width / last selected line: 0
  155. -- icon id / first selected line: 0 / 0
  156. -- text alignment: 0
  157. -- font id: 3
  158. -- text size: 12
  159. -- style flags: 0
  160. -- line height: 16
  161. -- part name: got
  162.  
  163.  
  164. -- part 12 (field)
  165. -- low flags: 01
  166. -- high flags: 0004
  167. -- rect: left=281 top=289 right=325 bottom=465
  168. -- title width / last selected line: 0
  169. -- icon id / first selected line: 0 / 0
  170. -- text alignment: 0
  171. -- font id: 0
  172. -- text size: 12
  173. -- style flags: 0
  174. -- line height: 16
  175. -- part name: 
  176.  
  177.  
  178. -- part contents for card part 5
  179. ----- text -----
  180. SerialHandler version 1.0a2
  181. Roger Brown
  182.  
  183. Serialhandler is a HyperCard XFCN that opens access to the Macintosh serial ports. Several functions are available through the one handler. Each is specified by an opcode in the first parameter. Successive parameters and the return value depend on the opcode.
  184.  
  185. OPCODE          INPUT                              DEFAULT                              OUTPUT
  186. =======         =====                          =======                             =======
  187. "open "             port  (A,B)                     A = modem                           error messages
  188.                          baud (300-9600)        9600                                    if any, or a handle
  189.                          data bits (5-8)              8                                          to the input buffer if
  190.                          parity (odd,even,none)  none                                     one larger than 64
  191.                          stop bits (1,1.5,2)       1                                           bytes is requested
  192.                          flow control 
  193.                            (XON/XOFF,CTS)          XON/XOFF
  194.                          input buffer size            64  bytes                   
  195.  
  196. "close"              port (A,B)                    A = modem                           none
  197.                          input buffer                  (optional)
  198.  
  199. "put"                 port (A,B)                    A = modem                          error messages
  200.                           source of characters     none
  201.  
  202. "get"                 port (A,B)                     A = modem                           error messages if any,                 
  203.                          timeout (ticks)             30  (1/2 sec)                          or characters received
  204.                        
  205. INVOKING SerialHandler
  206.  
  207.   get SerialHandler(task,port,...)
  208.         
  209.    where   task  is the opcode: open,close,put,or get
  210.                 port is the port to use
  211.                 ... other parameters as in the table above
  212.  
  213. EXAMPLES
  214.  
  215.      1. Opening with no parameters beyond the opcode will give you the defaults.  
  216.           ex. get SerialHandler("open")
  217.   
  218.      2. If you want an input buffer larger than 64 bytes then you must declare a global                   
  219.           variable to be used for only this purpose. Assign the return result of the open call 
  220.           to this global. It will be locked until you close the serial port. 
  221.  
  222.         ex. On OpenPort
  223.                  global serialBuffer       -- declare the global here
  224.                  put SerialHandler("open","A","4800,8,none,1,CTS,1024) into serialBuffer
  225.                   -- open the port and assign a 1024 byte buffer which is global serialBuffer
  226.                  if serialBuffer is not empty then put serialBuffer  -- show any error message
  227.              end OpenPort
  228.  
  229.              on ClosePort
  230.                 global serialBuffer
  231.                 get SerialHandler("close","A",serialBuffer) -- close port, set the input buffer 
  232.                 -- size  to zero and unlock it
  233.               end closePort 
  234.  
  235.    3. When getting characters from the port, the timeout parameter is the minimum time 
  236.         that SerialHandler will wait for input. If there are still characters to be read at the 
  237.         end of the timeout period, SerialHandler will keep on reading until there are no more 
  238.         to be read.
  239.  
  240.         ex. put SerialHandler("get","A",60) into charsRecieved
  241.  
  242.     4. get Serialhandler("put","A",the script of this stack) will send the text of the script
  243.         out serial port A, assuming it has been opened.
  244.  
  245. REVISION HISTORY
  246. 1.0a0 7/5/88 alpha release 
  247. 1.0a1 7/11/88 mistake in GetSerialChars  - 1st call to SetGetBuff had AinRefNum 
  248.            instead of   port as input
  249. 1.0a2 12/9/88 Call to ResultIs with an empty string was leaving orphan handles in the
  250.           heap.  Also, changed for compilation under LSC 3.0.
  251.  
  252.  
  253. -- part contents for card part 8
  254. ----- text -----
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                          
  263.  
  264.  
  265.  Alas, this demonstration will show you 
  266. nothing of interest unless you have a 
  267. serial device attached to the modem port 
  268. of your Mac. Like an Imagewriter, or a 
  269. terminal if you want to get input. 
  270.  
  271. -- part contents for card part 12
  272. ----- text -----
  273. Source not in the public domain, sorry.
  274.  
  275. -- part contents for card part 11
  276. ----- text -----
  277. Characters received on the serial port will appear below:
  278.  
  279.